const http = require('http')
const fs   = require('fs')
const config = require('./config')

const server = http.createServer((req, res) => {
    // 用户输入的url
    const url = req.url

    if (url === '/') {
        fs.readFile('./static/index.html', (err, data) => {
            res.writeHead(200, {'Content-Type': 'text/html;charset=UTF-8'})
            res.end(data)
        })
    } else {
        fs.readFile('./static/404.html', (err, data) => {
            res.writeHead(200, {'Content-Type': 'text/html;charset=UTF-8'})
            res.end(data)
        })
    }
})

server.listen(config.port, config.hostname, () => {
    console.log(`server listen on port ${config.port}`)
})